package cn.hj.org.service.impl;

import cn.hj.basic.service.impl.BaseServiceImpl;
import cn.hj.basic.util.PageList;
import cn.hj.org.domain.Department;
import cn.hj.org.mapper.DepartmentMapper;
import cn.hj.org.query.DepartmentQuery;
import cn.hj.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.BreakIterator;
import java.util.List;

@Service
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 查询部门树
     * @return
     */
    @Override
    public List<Department> findTree() {
        return departmentMapper.selectTree();
    }

    /**
     * 新增一条数据
     * @param department
     */
    @Override
    @Transactional
    public void insert(Department department) {
        departmentMapper.insert(department);
            this.update(department);
    }

    /**
     * 修改一条数据
     * @param department
     */
    @Override
    @Transactional
    public void update(Department department) {
        String path = null;
        if(department.getDepartment()==null){
            path = "/"+department.getId();
         }else {
            Department department1 = departmentMapper.selectById(department.getDepartment().getId());
            path = department1.getDirPath()+"/"+department.getId();
        }
        department.setDirPath(path);
        departmentMapper.update(department);
    }
}
